library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✔ ggplot2 3.3.6 ✔ purrr 0.3.4
## ✔ tibble 3.1.7 ✔ dplyr 1.0.9
## ✔ tidyr 1.2.0 ✔ stringr 1.4.0
## ✔ readr 2.1.2 ✔ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
data <- diamonds
library(gapminder)
gapminder
## # A tibble: 1,704 × 6
## country continent year lifeExp pop gdpPercap
## <fct> <fct> <int> <dbl> <int> <dbl>
## 1 Afghanistan Asia 1952 28.8 8425333 779.
## 2 Afghanistan Asia 1957 30.3 9240934 821.
## 3 Afghanistan Asia 1962 32.0 10267083 853.
## 4 Afghanistan Asia 1967 34.0 11537966 836.
## 5 Afghanistan Asia 1972 36.1 13079460 740.
## 6 Afghanistan Asia 1977 38.4 14880372 786.
## 7 Afghanistan Asia 1982 39.9 12881816 978.
## 8 Afghanistan Asia 1987 40.8 13867957 852.
## 9 Afghanistan Asia 1992 41.7 16317921 649.
## 10 Afghanistan Asia 1997 41.8 22227415 635.
## # … with 1,694 more rows
ca <- read_csv("https://raw.githubusercontent.com/ScienceParkStudyGroup/r-lesson-based-on-ohi-data-training/gh-pages/data/ca.csv")
## Rows: 789 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (5): region, state, code, park_name, type
## dbl (2): visitors, year
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
glimpse(ca)
## Rows: 789
## Columns: 7
## $ region <chr> "PW", "PW", "PW", "PW", "PW", "PW", "PW", "PW", "PW", "PW", …
## $ state <chr> "CA", "CA", "CA", "CA", "CA", "CA", "CA", "CA", "CA", "CA", …
## $ code <chr> "CHIS", "CHIS", "CHIS", "CHIS", "CHIS", "CHIS", "CHIS", "CHI…
## $ park_name <chr> "Channel Islands National Park", "Channel Islands National P…
## $ type <chr> "National Park", "National Park", "National Park", "National…
## $ visitors <dbl> 1200, 1500, 1600, 300, 15700, 31000, 33100, 32000, 24400, 31…
## $ year <dbl> 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, …
1st Plot
ggplot(ca, aes(x = year, y = visitors, colour = park_name)) +
geom_point(alpha = 0.5) +
labs( x= "Year", y= "Visitors", title= "California National Park Visitation" ) +
theme_minimal() +
theme(
legend.title = element_blank()
)
ggplot(ca, aes(x = year, y = visitors)) +
geom_point(alpha = 0.5, ) +
theme_light()
unique(ca$state)
## [1] "CA"
library(gapminder)
library(tidyverse)
gapminder <- gapminder
ggplot(gapminder, aes(x = log(gdpPercap),col= year, y = lifeExp, size = pop)) +
geom_point(alpha= 0.3, color = "#8d228d") +
geom_smooth(method = lm) +
facet_wrap(~continent, scales = "free") +
theme_bw()
## `geom_smooth()` using formula 'y ~ x'
## Ex.
library(tidyverse)
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
data <- read_csv("https://raw.githubusercontent.com/ScienceParkStudyGroup/r-lesson-based-on-ohi-data-training/gh-pages/data/se.csv")
## Rows: 453 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (5): region, state, code, park_name, type
## dbl (2): visitors, year
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
plot <- ggplot(data, aes(x = park_name, y = visitors, col = park_name)) +
geom_boxplot() +
geom_jitter(alpha = .3) +
coord_flip() +
theme_bw() +
theme(
legend.position = "none"
)
ggplotly(plot)